home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
idioms.lha
/
idioms
/
2-2b.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
623b
|
43 lines
/* Copyright (c) 1992 by AT&T Bell Laboratories. */
/* Advanced C++ Programming Styles and Idioms */
/* James O. Coplien */
/* All rights reserved. */
const int STACK_SIZE = 10;
class Stack {
private:
long items[STACK_SIZE];
int sp;
public:
void initialize();
long top() const;
long pop();
void push(long);
};
void Stack::initialize() {
sp = -1;
}
long Stack::top() const {
return items[sp];
}
long Stack::pop() {
return items[sp--];
}
void Stack::push(long i) {
items[++sp] = i;
}
int main()
{
Stack q;
q.initialize();
q.push(1);
int i = q.top();
q.pop();
}